capture program drop interact_graph
program define interact_graph
	version 9.1
	syntax varlist [if] [in] , xtitle(string) 
	preserve
	marksample touse
	qui keep if `touse'
	tokenize "`varlist'"



	matrix b=e(b)
	matrix V=e(V)


	
	matrix b1=b["y1", `"`1'"' ]
	matrix b2=b["y1",`"`2'"']
	matrix b3=b["y1",`"`3'"']



	matrix var1=V[ `"`1'"',  `"`1'"']
	matrix var2=V[ `"`2'"',  `"`2'"']
	matrix var3=V[ `"`3'"',  `"`3'"']



	matrix cov12=V[`"`1'"', `"`2'"']
	matrix cov13=V[`"`1'"', `"`3'"']
	matrix cov23=V[`"`2'"', `"`3'"']




	scalar b1=trace(b1)
	scalar b2=trace(b2)
	scalar b3=trace(b3)


	scalar var1 = trace(var1)
	scalar var2 = trace(var2)
	scalar var3 = trace(var3)
	
	scalar cov12 = trace(cov12)
	scalar cov13 = trace(cov13)
	scalar cov23 = trace(cov23)


drop if _n>100
gen xaxis= ((_n)/100)
gen margeff=b1+b3*xaxis
gen sterror=sqrt(var1+var3*(xaxis)^2+2*(xaxis)*cov13)



gen a=1.65*sterror
gen conf_U=margeff+a
gen conf_L=margeff-a


line margeff  xaxis || line conf_U xaxis, lp(dash) lcolor(black)  || line conf_L xaxis,   lp(dash) lcolor(black) legend(off)  xtitle(`xtitle') ytitle("Marginal effect")  ylab(-3(0.5)1, angle(horizontal))  xlab(0(0.1)1) yline(0, lcolor(red)) 

	
restore	
end
